(function (w) {
    var rewardList = function () {
        this.Init();
        return this;
        },iscroll = {},page = 1,scrollControl = false,
        reqControl = true,scrollEnd = false,
        giftActivityObjId = getQueryString("giftActivityObjId"),
        userObjId = getQueryString("userObjId");
    rewardList.prototype = {
        Init: function () {
            this.data = {"url":cw.serverUrl+"/rest/v1.0/lottery/getLotteryAwardList/"+ userObjId +"/" + giftActivityObjId +"/"+ page};
            netWork(this.data,this.listHandle);

            var c = this;
            iscroll = new iScroll("scroll_list", { "useTransition": true, "vScrollbar": false, "hScroll": false, "onScrollStart": function () {
                scrollControl = true;
            }, "onScrollEnd": function () {
                //if(scrollControl){}
                if(scrollEnd == true){return;}
                if(reqControl){
                    reqControl = false;
                    c.data = {"url":cw.serverUrl+"/rest/v1.0/lottery/getLotteryAwardList/"+ userObjId +"/" + giftActivityObjId +"/"+ page,"loading": c.listload,"endLoading": c.removeloading};
                    netWork(c.data,c.listHandle);
                }
            }});
        },
        listHandle: function(data){
            var d = eval( "(" + data + ")"),html = "";
            //if(!d.data&&page == 1){
            //    document.getElementById("reward_list").innerHTML += "<li id = 'scroll_tip'>暂时还木有邻居中奖，快去拼手气！</li>";
            //    return;
            //}
            if(d.data&&d.data.length == 0 && !scrollEnd){
                scrollEnd = true;
                if(page == 1){
                    document.getElementById("reward_list").innerHTML += "<li id = 'scroll_tip'>暂时还木有邻居中奖，快去拼手气！</li>";
                    scrollEnd = false;
                }else{
                    document.getElementById("reward_list").innerHTML += "<li id = 'scroll_tip'>没有更多数据了</li>";
                }
                iscroll.refresh();
                return;
            }
            for(var i = 0;i < d.data.length;i++){
                var date = new Date(d.data[i].time);
               html += "<li><img src='"+d.data[i].images+"' onerror = 'defaultImg(this)'/> <div class = 'Lottery'><span class = 'name-address ell'><span id = 'name' class = 'ell'>"+ d.data[i].nickName +"</span><span class = 'ell'>"+ d.data[i].roomUnit +"单元</span></span><br> <span>"+ d.data[i].awardNum+"&nbsp;&nbsp;"+d.data[i].prize +"</span> </div> <div class = 'reward-time'>"+resetNum(date.getFullYear())+"-"+resetNum(date.getMonth()+1)+"-"+resetNum(date.getDate())+" "+ resetNum(date.getHours())+":"+ resetNum(date.getMinutes()) +"</div> <div class = 'clear'></div></li>";//resetNum(date.getMonth()+1) +"-"+resetNum(date.getDate())+ "-"+
            }
            document.getElementById("reward_list").innerHTML += html;
            iscroll.refresh();
            if(page == 1){
                document.getElementById("loading").style.display = "none";
            }
            page++;
            reqControl = true;
            //iscroll.refresh();
        },
        listload: function(){
            document.getElementById("reward_list").innerHTML += "<li id = 'scroll_tip'>正在加载中...</li>";
            iscroll.refresh();
        },
        removeloading: function(){
            document.getElementById("reward_list").removeChild(document.getElementById("scroll_tip"));
            reqControl = true;
            iscroll.refresh();
        },
        evt: function(){
            //document.getElementById("refresh").addEventListener('touchend', function (e) { location.reload(); }, false);
            document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
        }
    }

    var resetNum = function(num){
        if(num < 10) num = "0"+num;
        return num;
    };
    w.rewardList = rewardList;
})(window);
var defaultImg = function(th){
    th.src = cw.resUrl+"images/reward/portrait_normal.jpg";
};
new rewardList().evt();